package com.vrv.common.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.vrv.netmgr.R;

/**
 * 实现多级list的listview适配器
 * 
 * @author 曹保利
 * 
 */
public class MultistageListAdapter extends BaseAdapter {

	private List<Map<String, Object>> dataSource = new ArrayList<Map<String, Object>>();

	private List<Map<String, Object>> childs = new ArrayList<Map<String, Object>>();

	private Context mContext;

	public MultistageListAdapter() {
		super();
	}

	public MultistageListAdapter(Context mContext, List<Map<String, Object>> dataSource) {
		super();
		this.mContext = mContext;
		this.dataSource = dataSource;
	}

	@Override
	public int getCount() {
		return dataSource.size();
	}

	@Override
	public Object getItem(int position) {
		return dataSource.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressWarnings("unchecked")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		RelativeLayout view = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.list_item_multistage, null);
		TextView tv = (TextView) view.findViewById(R.id.itemTxt);
		ImageView icon = (ImageView) view.findViewById(R.id.arrow_icon);

		tv.setText(dataSource.get(position).get("label").toString());

		childs = (List<Map<String, Object>>) dataSource.get(position).get("child");
		if (childs != null && childs.size() > 0) {
			icon.setVisibility(View.VISIBLE);
		} else {
			icon.setVisibility(View.INVISIBLE);
		}
		return view;
	}
}
